const BaseHandler     = require('../base-handler');
const SystemServices  = require('../../../constants').SystemServices;
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;
const utils           = require('../../../utils');

class CollectHandler extends BaseHandler {
    get pattern() {
        return "/leadflow/:leadflow_id/collect";
    }

    doGET(request, response) {
        var data = request.query;
        data.user_agent = request.headers['user-agent'];
        data.remote_ip = utils.getRemoteIP(request);
        data.session_id = request.sessionID;
        data.http_referer = request.headers['referer'];
        this.Controller.saveCollectedLead(request.params.leadflow_id, data, (result) => {
            response.json(result);
        });
    }

    doPOST(request, response) {
        var data = request.body;
        data.user_agent = request.headers['user-agent'];
        data.remote_ip = utils.getRemoteIP(request);
        data.session_id = request.sessionID;
        this.Controller.saveCollectedLead(request.params.leadflow_id, data, (result) => {
            response.json(result);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
        this.registerVerb(HTTP_VERBS.POST, this.doPOST);
    }
}

module.exports = CollectHandler;